********************************************************************************
* 							 PROCESS AND CLEAN DATA							   *
********************************************************************************

clear all
set more off
set scheme plotplainblind
macro drop _all
est drop _all
set matsize 800
set seed 8675309

** Set Working Directory

if c(username) == "christopherblair"{
global dir "~/Desktop/JOP Replication"
global raw "${dir}/Raw Files"
global code "${dir}/Code"									
}

else if c(username) == "youruser"{
global dir "~/Desktop/JOP Replication"
global raw "${dir}/Raw Files"
global code "${dir}/Code"	
}

cd "${raw}"

********************************************************************************

** Load from Dictionary

infile using "ams175.dct", clear

cd "$dir"
sort cardnum surveynum ballotnum
save "${dir}/ams175.dta", replace

drop notused

label define rank 0 "No Answer" 1 "PRV. or PFC." 2 "CPL or TCH5" 3 "SGT or TCH4" 4 "SSGT or TCH3" 5 "TSGT, MSGT, 1SGT"
label val rankgrade rank
label define age 0 "No Answer" 1 "18 or Less" 2 "19" 3 "20" 4 "21" 5 "22" 6 "23" 7 "24" 8 "25" 9 "26-29" 10 "30-34" 11 "35+"
label val age age
label define edu 0 "No Answer" 1 "<8th Grade" 2 "8th Grade" 3 "Some High School" 4 "High School" 5 "College"
label val school edu
label define time 0 "No Answer" 1 "3 Months or Less" 2 "3-6 Months" 3 "6-9 Months" 4 "9-12 Months" 5 "12-18 Months" 6 "18-24 Months" 7 "24-30 Months" 8 "30-36 Months" 9 "36+ Months"
label val monthsoversea time
label define activities 0 "No Answer" 1 "Yes, I do" 2 "No, I don't"
label val honoluluactivities activities
label define honolulu 0 "No Answer" 1 "Every time" 2 "About half the time" 3 "Just once in awhile" 4 "Hardly ever"
label val honoluluvisit honolulu
label define masktype 0 "No Answer" 1 "New Type Mask" 2 "Old Type Mask" 3 "Not Sure" 4 "No Mask"
label val gasmasktype masktype
label define gastrain 0 "No Answer" 1 "Absolutely Necessary" 2 "Great Importance" 3 "Medium Importance" 4 "Little Importance" 5 "No Importance"
label val gastrainingimportance gastrain
label define wear 0 "No Answer" 1 "1" 2 "2" 3 "3" 4 "4" 5 "0"
label val gasmaskusage wear
label define wearopinion 0 "No Answer" 1 "Very Good Idea" 2 "Fairly Good Idea" 3 "Very Poor Idea" 4 "Poor Idea"
label val gasmaskusageopinion wearopinion
label define chamber 1 "1" 2 "2" 3 "3+" 4 "0"
label val gaschamber chamber
label define chamberopinion 0 "No Answer" 1 "Very Good Idea" 2 "Fairly Good Idea" 3 "Very Poor Idea" 4 "Poor Idea"
label val gaschamberopinion chamberopinion
label define maskconf 0 "No Answer" 1 "A Great Deal" 2 "A Fair Amount" 3 "Not So Much" 4 "Hardly Any"
label val gasmaskconf maskconf
label define protect 0 "No Answer" 1 "Yes" 2 "Yes, but not sure" 3 "No" 4 "Undecided"
label val japangasattack protect
label define use 0 "No Answer" 1 "Use Gas by Surprise" 2 "Use Gas if Japan Does" 3 "Should Not Use Gas" 4 "Undecided"
label val gasusageopinion use
label define likely 0 "No Answer" 1 "Very Likely" 2 "Fairly Likely" 3 "Not so Likely" 4 "Not Likely" 5 "Undecided"
label val japangasopinion likely
label define diduse 0 "No Answer" 1 "Yes" 2 "No" 3 "Don't Know"
label val japangasamerknowledge diduse
label val japangasaustknowledge diduse
label val japangasbritknowledge diduse
label val japangaschinknowledge diduse
label define worth 0 "No Answer" 1 "Very Much Worthwhile" 2 "Fairly Worthwhile" 3 "Not So Worthwhile" 4 "Not Worthwhile" 5 "Undecided"
label val orientmeetopinion worth
label define attend 0 "No Answer" 1 "< Weekly" 2 "Weekly" 3 "> Weekly" 4 "Never" 5 "No Meetings Held"
label val orientmeetfreq attend
label define lead 0 "No Answer" 1 "Officer" 2 "Enlisted Man" 3 "Makes No Difference"
label val orientmeetleadopinion lead
label define knowstuff 0 "No Answer" 1 "Always" 2 "Usually" 3 "Seldom" 4 "Never" 5 "No Meetings Held"
label val oriemtmeetknowledge knowstuff
label define meetinterest 0 "No Answer" 1 "All" 2 "Most" 3 "Half" 4 "Few" 5 "None" 6 "No Meetings Held"
label val orientmeetinterest meetinterest
label define teach 0 "No Answer" 1 "Alot" 2 "Somewhat" 3 "Hardly at all" 4 "No Meetings Held"
label val orientmeetteach teach
label define interest 0 "No Answer" 1 "Very Interested" 2 "Not so Interested" 3 "Not Interested at All"
label val usaffairsinterest interest
label val usprobinterest interest
label val usworldaffairsinterest interest
label val ussoldierretireinterest interest
label val enemyfactsinterest interest
label val allyfactsinterest interest
label val warjapaninterest interest
label val wargermaninterest interest
label val peaceprobinteret interest
label val centpacificinterest interest
label define discuss 0 "No Answer" 1 "Always" 2 "Usually" 3 "Seldom" 4 "Never" 5 "No Meetings Held"
label val postmeetchat discuss
label define share 0 "No Answer" 1 "Yes" 2 "No"
label val orientmeetpartic share
label val orientmeetofficerattend share
label define giveopinion 0 "No Answer" 1 "Often" 2 "Sometimes" 3 "Seldom" 4 "Never" 5 "No Chance for Input"
label val orientmeetparticfreq giveopinion
label define officertalk 0 "No Answer" 1 "More Discussion When Officers Attend" 2 "Less Discussion When Officers Attend" 3 "Makes No Difference" 4 "No Chance for Input"
label val meetdiscussionofficers officertalk
label define infocenter 0 "No Answer" 1 "Yes" 2 "No" 3 "Don't Know"
label val warintcentnear infocenter
label define infocenterfreq 0 "No Answer" 1 "< Weekly" 2 "Once a Week" 3 "1-2 Times a Week" 4 "3-4 Times a Week" 5 "Daily" 6 "Never" 7 "No Information Center"
label val warintcentusage infocenterfreq
label define infohelp 0 "No Answer" 1 "Alot" 2 "Somewhat" 3 "Hardly at All" 4 "No Information Center"
label val warintcenthelpful infohelp
label define toldclass 0 "No Answer" 1 "Yes" 2 "No" 3 "Not Sure"
label val offdutycourseaware toldclass
label define takeclass 0 "No Answer" 1 "Yes, in course" 2 "Yes, interested" 3 "No"
label val offdutycourseinterest takeclass
label define important 0 "No Answer" 1 "Very Important" 2 "Fairly Important" 3 "Not So Important" 4 "Not Important At All"
label val calisthenimportant important
label val swimimportant important
label val orientimportant important
label val gasmaskimportant important
label val drillimportant important
label val guncareimportant important
label val dryfireimportant important
label val rangefireimportant important
label val firstaidimportant important
label val gaschamberimportant important
label val hikesimportant important
label val obstcourseimportant important
label define allies 0 "No Answer" 1 "Very Well" 2 "Disagree, But Get Along" 3 "Disagree, But Won't Fight" 4 "Will Fight" 5 "Undecided"
label val chinarelatpostwar allies
label val russrelatpostwar allies
label val englrelatpostwar allies
label define schedule 0 "No Answer" 1 "< Weekly" 2 "Once a Week" 3 "> Weekly" 4 "Not At All" 5 "Don't Know"
label val schedorientmeet schedule
label define basetrain 1 "Hickam -- CW Training" 2 "Hickam -- No Training" 3 "Wheeler -- No Training" 4 "Mokuleia -- CW Training" 5 "Bellows -- CW Training" 6 "Bellows -- No Training" 7 "Kahulu -- CW Training" 8 "Kahulu -- No Training"
label val basechemwartrain basetrain

save "${dir}/ams175.dta", replace


** Generate Key Variables for Analysis

gen use=(gasusageopinion==1 | gasusageopinion==2)
replace use=. if gasusageopinion==0
label var use "US Should Use CW (=1)"

gen dontuse=(gasusageopinion==3 | gasusageopinion==4)
replace dontuse=. if gasusageopinion==0
label var dontuse "US Should Not Use CW/Undecided (=1)"

gen firstuse=(gasusageopinion==1)
replace firstuse=. if gasusageopinion==0
label var firstuse "US Should Use CW Preemptively (=1)"

gen seconduse=(gasusageopinion==2)
replace seconduse=. if gasusageopinion==0
label var seconduse "US Should Use CW in Retaliation (=1)"

gen undecided=(gasusageopinion==4)
replace undecided=. if gasusageopinion==0
label var undecided "Not Sure if US Should Use CW (=1)"

gen refrain=(gasusageopinion==3)
replace refrain=. if gasusageopinion==0
label var refrain "US Should Not Use CW (=1)"

gen use3=.
replace use3=2 if gasusageopinion==1
replace use3=1 if gasusageopinion==2
replace use3=0 if gasusageopinion==3 | gasusageopinion==4
label var use3 "Support for CW Use (3 Categories)"

gen use4=.
replace use4=3 if gasusageopinion==1
replace use4=2 if gasusageopinion==2
replace use4=1 if gasusageopinion==4
replace use4=0 if gasusageopinion==3
label var use4 "Support for CW Use (4 Categories)"

gen base=.
replace base=1 if basechemwartrain==1 | basechemwartrain==2
replace base=2 if basechemwartrain==3
replace base=3 if basechemwartrain==4
replace base=4 if basechemwartrain==5 | basechemwartrain==6
replace base=5 if basechemwartrain==7 | basechemwartrain==8
label define base 1 "Hickam" 2 "Wheeler" 3 "Mokuleia" 4 "Bellows" 5 "Kahulu"
label val base base
label var base "Base"

gen training=0
replace training=1 if basechemwartrain==1 | basechemwartrain==4 | basechemwartrain==5 | basechemwartrain==7
label define training 0 "No Training" 1 "CW Training"
label val training training
label var training "Training Regimen"

gen mask=(inrange(gasmaskusage,1,4))
label var mask "Used Gas Mask (=1)"
gen nomask=(gasmaskusage==5)
label var nomask "Never Used Gas Mask (=1)"
gen mask_nr=(gasmaskusage==0)
label var mask_nr "Gas Mask Non-Response (=1)"

gen nummask=0
replace nummask=1 if gasmaskusage==1
replace nummask=2 if gasmaskusage==2
replace nummask=3 if gasmaskusage==3
replace nummask=4 if gasmaskusage==4
label var nummask "Gas Mask Frequency"

gen nummask_miss=.
replace nummask_miss=0 if gasmaskusage==5
replace nummask_miss=1 if gasmaskusage==1
replace nummask_miss=2 if gasmaskusage==2
replace nummask_miss=3 if gasmaskusage==3
replace nummask_miss=4 if gasmaskusage==4
label var nummask_miss "Gas Mask Frequency (Non-Response Dropped)"

gen chamber=(inrange(gaschamber,1,3))
label var chamber "Used Gas Chamber (=1)"
gen nochamber=(gaschamber==4)
label var nochamber "Never Used Gas Chamber (=1)"

gen numchamber=0
replace numchamber=1 if gaschamber==1
replace numchamber=2 if gaschamber==2
replace numchamber=3 if gaschamber==3
label var numchamber "Gas Chamber Frequency"

gen multiple_chamber=(numchamber>=2 & numchamber!=.)
label var multiple_chamber "Multiple Exposure to Gas Chamber (=1)"

gen newmask=(gasmasktype==1)
label var newmask "New Gas Mask (=1)"

gen confidence3=.
replace confidence3=0 if gasmaskconf==4 | gasmaskconf==3
replace confidence3=1 if gasmaskconf==2
replace confidence3=2 if gasmaskconf==1
gen highconfid=(gasmaskconf==1)
replace highconfid=. if gasmaskconf==0
gen lowconfid=(gasmaskconf==4 | gasmaskconf==3)
replace lowconfid=. if gasmaskconf==0
replace highconfid=. if gasmaskconf==0
label var confidence3 "Confidence in Gas Mask"
label var lowconfid "Low Confidence in Gas Mask (=1)"
label var highconfid "High Confidence in Gas Mask (=1)"

gen protect3=.
replace protect3=0 if japangasattack==4 | japangasattack==3
replace protect3=1 if japangasattack==2
replace protect3=2 if japangasattack==1
gen highprotect=(japangasattack==1)
replace highprotect=. if japangasattack==0
gen lowprotect=(japangasattack==4 | japangasattack==3)
replace lowprotect=. if japangasattack==0
replace highprotect=. if japangasattack==0
label var protect3 "Protect Yourself in Gas Attack"
label var lowprotect "Low Confidence in Protect Yourself (=1)"
label var highprotect "High Confidence in Protect Yourself (=1)"

gen gaslikelyuse=(japangasopinion==1 | japangasopinion==2)
gen us_use=(japangasamerknowledge ==1)
gen aus_use=(japangasaustknowledge ==1)
gen brit_use=(japangasbritknowledge ==1)
gen china_use=(japangaschinknowledge ==1)
label var gaslikelyuse "Japan Likely to Use CW (=1)"
label var us_use "Japan Used CW on US (=1)"
label var aus_use "Japan Used CW on Australia (=1)"
label var brit_use "Japan Used CW on UK (=1)"
label var china_use "Japan Used CW on China (=1)"
swindex us_use aus_use brit_use china_use, gen(use_history)
label var use_history "Previous Use Against Allies (ICW)"
gen correct_history=(us_use==0 & aus_use==0 & brit_use==0 & china_use==1)
label var correct_history "Knows History of Use Against Allies (=1)"

gen orient_worth=(orientmeetopinion==1 | orientmeetopinion==2)
label var orient_worth "Orientation Meetings Worthwhile (=1)"
gen orient_meet=(orientmeetfreq==2 | orientmeetfreq==3)
label var orient_meet "Attend Orientation Meetings Weekly (=1)"
gen orient_nomeet=(orientmeetfreq==5)
label var orient_nomeet "No Orientation Meetings Held (=1)"
gen orient_offlead=(orientmeetleadopinion==1)
label var orient_offlead "Prefer Officers Lead Orientation Meetings (=1)"
gen orient_enllead=(orientmeetleadopinion==2)
label var orient_enllead "Prefer Enlisted Men Lead Orientation Meetings (=1)"
gen orient_offattend=(orientmeetofficerattend==1)
label var orient_offattend "Officers Attend Orientation Meetings (=1)"
gen officers_talk=(meetdiscussionofficers==1)
label var officers_talk "More Discussion When Officers Attend (=1)"
gen orient_effective=(oriemtmeetknowledge==1 | oriemtmeetknowledge==2)
label var orient_effective "Orientation Meetings Effective (=1)"
gen orient_interest=(orientmeetinterest==1 | orientmeetinterest==2)
label var orient_interest "Orientation Meetings Interesting (=1)"
gen orient_teach=(orientmeetteach==1)
label var orient_teach "Orientation Meetings Teach About War (=1)"
gen orient_partic=(orientmeetpartic==1)
label var orient_partic "Men Participate in Orientation Meetings (=1)"
gen orient_youpartic=(orientmeetparticfreq==1 | orientmeetparticfreq==2)
label var orient_youpartic "You Participate in Orientation Meetings (=1)"
gen orient_impt=(orientimportant==1 | orientimportant==2)
label var orient_impt "Orientation Meetings Important (=1)"
gen orient_talk=(postmeetchat==1 | postmeetchat==2)
label var orient_talk "Men Chat After Orientation (=1)"
gen orient_sched=(schedorientmeet==2 | schedorientmeet==3)
label var orient_sched "Orientation Meetings Scheduled Weekly (=1)"
swindex orient_meet orient_partic orient_youpartic orient_talk orient_sched, gen(orientation_particp)
label var orientation_particp "Orientation Participation (ICW)"
swindex orient_worth orient_interest orient_teach orient_impt orient_effective, gen(orientation_learn)
label var orientation_learn "Orientation Learning (ICW)"
swindex orient_offlead orient_offattend officers_talk, gen(orientation_officers)
label var orientation_officers "Officers' Leadership (ICW)"

gen interest1=(usaffairsinterest==1)
gen interest2=(usprobinterest==1)
gen interest3=(usworldaffairsinterest==1)
gen interest4=(ussoldierretireinterest==1)
gen interest5=(enemyfactsinterest==1)
gen interest6=(allyfactsinterest==1)
gen interest7=(warjapaninterest==1)
gen interest8=(wargermaninterest==1)
gen interest9=(peaceprobinteret==1)
gen interest10=(centpacificinterest==1)
swindex interest1-interest10, gen(general_interest)
label var general_interest "General News Interest (ICW)"
swindex interest3 interest5-interest10, gen(war_interest)
label var war_interest "War News Interest (ICW)"
drop interest1-interest10

gen infocenter=(warintcentnear==1)
label var infocenter "Information Center (=1)"
gen noinfocenter=(warintcentnear==2)
label var noinfocenter "No Information Center (=1)"
gen infocenter_visit=(warintcentusage==5 | warintcentusage==4)
label var infocenter_visit "Use Information Center 3+ Times Weekly (=1)"
gen infocenter_help=(warintcenthelpful==1)
label var infocenter_help "Information Center if Helpful (=1)"
swindex infocenter infocenter_visit infocenter_help, gen(information_center)
label var information_center "Information Center Access (ICW)"

gen courses1=(offdutycourseaware==1)
gen courses2=(offdutycourseinterest==1 | offdutycourseinterest==2)
gen incourse=(offdutycourseinterest==1)
label var incourse "In Off-Duty Course (=1)"
swindex courses1 courses2, gen(offduty_courses)
drop courses1 courses2
label var offduty_courses "Off-Duty Course Interest (ICW)"

gen honolulu1=(honoluluactivities==2)
gen honolulu2=(honoluluvisit==1)
swindex honolulu1 honolulu2, gen(honolulu_contact)
drop honolulu1 honolulu2
label var honolulu_contact "Local Contact (ICW)"

gen goodgastrain=(gastrainingimportance==1 | gastrainingimportance==2)
gen goodmasktrain=(gasmaskusageopinion==1 | gasmaskusageopinion==2)
gen maskimpt=(gasmaskimportant==1 | gasmaskimportant==2)
gen goodchambertrain=(gaschamberopinion==1 | gaschamberopinion==2)
gen chamberimpt=(gaschamberimportant==1 | gaschamberimportant==2)
swindex goodgastrain goodmasktrain goodchambertrain chamberimpt, gen(gas_training)
drop goodgastrain goodmasktrain goodchambertrain
label var maskimpt "Important to Train in Gas Masks (=1)"
label var chamberimpt "Important to Train in Gas Chamber (=1)"
label var gas_training "Gas Training Favorability (ICW)"

gen training1=(calisthenimportant==1 | calisthenimportant==2)
gen training2=(swimimportant==1 | swimimportant==2)
gen training3=(drillimportant==1 | drillimportant==2)
gen training4=(guncareimportant==1 | guncareimportant==2)
gen training5=(dryfireimportant==1 | dryfireimportant==2)
gen training6=(rangefireimportant==1 | rangefireimportant==2)
gen training7=(firstaidimportant==1 | firstaidimportant==2)
gen training8=(hikesimportant==1 | hikesimportant==2)
gen training9=(obstcourseimportant==1 | obstcourseimportant==2)
swindex training1 training2 training8 training9, gen(physical_training)
swindex training3-training7, gen(military_training)
drop training1-training9
label var physical_training "Physical Fitness Training (ICW)"
label var military_training "Military Skills Training (ICW)"

gen china_relations=(chinarelatpostwar==1)
gen ussr_relations=(russrelatpostwar==1)
gen brit_relations=(englrelatpostwar==1)
swindex china_relations ussr_relations brit_relations, gen(ally_relations)
drop china_relations ussr_relations brit_relations
label var ally_relations "Postwar Ally Relations (ICW)"

save "${dir}/ams175.dta", replace

************************************ IPTW **************************************

eststo clear

global core "rankgrade age school monthsoversea"
global addit "war_interest orient_meet infocenter orientation_officers honolulu_contact"
probit multiple_chamber i.($core) $addit, cluster(base)
predict pr_multiple, pr
gen iptw=.
replace iptw=1/pr_multiple if multiple_chamber==1
replace iptw=1/(1-pr_multiple) if multiple_chamber==0
drop pr_multiple
label var iptw "Inverse Probability of Treatment Weights"

eststo clear

*********************************** COMPLIANCE *********************************

gen complier=0
replace complier=1 if numchamber>0 & training==1
replace complier=1 if numchamber==0 & training==1 & monthsoversea==1
replace complier=1 if numchamber==0 & nummask>0 & training==0 & nummask!=.
replace complier=1 if numchamber==0 & nummask==0 & training==0 & nummask!=. & monthsoversea==1
label var complier "Complied With Treatment Assignment (=1)"

eststo clear

global core "rankgrade age school monthsoversea"
global addit "training orientation_officers"
probit complier i.($core) $addit i.base, cluster(base)
predict pr_complier, pr
label var pr_complier "Probability of Treatment Compliance"

eststo clear

*********************************** ENTROPY ************************************

eststo clear

gen somehs=(school>=3)
gen somecollege=(school==5)
gen age1525=(inrange(age,1,8))
gen age2634=(inrange(age,9,10))
gen age35=(age==11)

ebalance somehs somecollege age1525 age2634 age35, manual(0.568 0.123 0.499 0.413 0.088) generate(demweight)
label var demweight "Demographic Entropy Weights"
drop somehs somecollege age1525 age2634 age35

************************************* CEM **************************************

cem age(0(1)11) school(0(1)5) monthsoversea(0(1)9) rankgrade(0(1)5) infocenter(0 1) orient_meet(0 1) training(0 1) war_interest, treatment(chamber)

label var cem_strata "CEM Strata"
label var cem_matched "CEM Matched =(1)"
label var cem_weights "CEM Weights"
ren cem_strata cem_strata1
ren cem_matched cem_matched1
ren cem_weights cem_weights1

cem age(0(1)11) school(0(1)5) monthsoversea(0(1)9) rankgrade(0(1)5) infocenter(0 1) orient_meet(0 1) training(0 1) war_interest, treatment(multiple)

label var cem_strata "CEM Strata"
label var cem_matched "CEM Matched =(1)"
label var cem_weights "CEM Weights"
ren cem_strata cem_strata2
ren cem_matched cem_matched2
ren cem_weights cem_weights2

********************************* ADDITIONAL ***********************************

gen lowedu=.
replace lowedu=4 if school==1
replace lowedu=3 if school==2
replace lowedu=2 if school==3
replace lowedu=1 if school==4
replace lowedu=0 if school==5
replace lowedu=0 if school==0
label var lowedu "Education Scale (Reverse)"

gen use_comply=use
replace use_comply=. if complier==0
label var use_comply "US Should Use CW (=1) Conditional on Compliance"

********************************************************************************

save "${dir}/ams175.dta", replace

foreach x of var age school rankgrade monthsoversea base {
tab `x', gen(`x')
}

save "${dir}/ams175_R.dta", replace

********************************** DEMOGRAPHICS ********************************

eststo clear

gen somehs=(school==3)
gen somecollege=(school==5)
gen age1525=(inrange(age,1,8))
gen age2634=(inrange(age,9,10))
gen age35=(age==11)

sum age1525 age2634 age35 somehs somecollege monthsoversea
sum age1525 age2634 age35 somehs somecollege monthsoversea if chamber==1
sum age1525 age2634 age35 somehs somecollege monthsoversea if chamber==0

clear
